<?php
namespace app\controller;

use app\BaseController;
use app\model\Resource;
use app\model\UploadFile;
use think\Request;

/* 资源 */
class ResourceController extends BaseController
{
    public function resourceList(Request $request)
    {
        $post = $request->param();
        $user = auth_user($request);
        $where = [];
        $list = Resource::where($where)->page($request->param('page') ?? 1, $request->param('pageSize') ?? 10)->select();
        // exit(OutdoorTrack::getlastSql());
        return pageReturn($list, $request);
    }
    public function addResource(Request $request)
    {
        $Resource = new Resource;
        $data = $request->post();
        if ($Resource) {
            foreach ($data as $key => $value) {
                $Resource->$key = stripslashes($value);
            }
        }
        $rq = $Resource->save();
        if ($rq) {
            return success($request);
        }
    }
    public function selectResource(Request $request)
    {
        $list = Resource::select();
        return success($list->visible(['id','class','type']));
    }
    public function delResource(Request $request)
    {
        $id = $request->param('id');
        $Resource = Resource::find($id);
        // $rq = $Resource->destroy($id);
        $rq = $Resource->force()->delete(); //直接删除
        if ($rq) {
            return success($request);
        }
    }
}
